package com.example.finance_manager.pages.manage;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.finance_manager.R;
import com.example.finance_manager.dao.FlagDao;
import com.example.finance_manager.models.Flag;

public class FlagManageActivity extends AppCompatActivity {

    private EditText etContain;
    private Button btnSave;
    private Button btnCancel;
    private FlagDao flagDao;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manage_flag);

        flagDao = new FlagDao(this);

        initView();
        initListener();
    }

    private void initView() {
        etContain = (EditText) findViewById(R.id.et_manage_flag_content);
        btnSave = (Button) findViewById(R.id.btn_manage_flag_save);
        btnCancel = (Button) findViewById(R.id.btn_manage_flag_cancel);
    }

    private void initListener() {
        btnSave.setOnClickListener(view -> {
            String contain = etContain.getText().toString();
            Flag flag = new Flag(contain);
            flagDao.add(flag);
            Toast.makeText(FlagManageActivity.this, "保存成功", Toast.LENGTH_LONG).show();
        });
        btnCancel.setOnClickListener(view -> {
            finish();
        });
    }
}